Ext.define('Admin.view.decMakConsultation.ProgramDecisionController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.programDecision',
    onNewConsultationClick: function() {
        var me = this;
        var yxfa = me.getView().query('combobox[dicType=yxfa]')[0].getValue();
        if (yxfa == '001') {
            me.redirectTo('newConsultation1');
        } else if (yxfa == '002') {
            me.redirectTo('newConsultation');
        } else {
            me.redirectTo('newConsultation1');
        }
    },

    //会商管理查询
    meetingSearch: function() {
        var meetingGrid = this.lookupReference('meetingGrid');
        var store = meetingGrid.getStore();
        var MEETING_TYPE = this.lookupReference('MEETING_TYPE').getValue();
        var MEETING_NAME = this.lookupReference('MEETING_NAME').getValue();
        // var MEETING_STIME = Ext.Date.format(this.lookupReference('MEETING_STIME').getValue(), 'Y-m-d')
        // var MEETING_ETIME = Ext.Date.format(this.lookupReference('MEETING_ETIME').getValue(), 'Y-m-d')
        store.getProxy().extraParams = {
            river: config.RIVER,
            conType: MEETING_TYPE,
            conName: MEETING_NAME,
            // startTm: MEETING_STIME,
            // endTm: MEETING_ETIME,
        };
        store.reload();
    },

    //删除动作
    meetingDel: function(grid, rowIndex, colIndex) {
        var conId = grid.getStore().getAt(rowIndex).get('conId');
        Ext.Msg.confirm("警告", "确定要删除吗？", function(button) {
            if (button === 'yes') {
                Ext.Ajax.request({
                    url: config.URL + '/szy/dispatch/meeting/ddsSCon/delete',
                    method: "post",
                    success: function(response, opts) {
                        Ext.MessageBox.hide();
                        var result = Ext.JSON.decode(response.responseText);
                        if (result.code === 1) {
                            grid.store.load();
                            Ext.Msg.alert('系统提示', "删除成功");
                        } else {
                            Ext.Msg.alert("系统提示", '删除失败');
                        }
                    },
                    failure: function() {
                        Ext.Msg.alert('系统提示', '系统出错！');
                    },
                    params: { conId: conId, river: config.RIVER }
                });
            }
        })
    },

    //新增会商
    meetingAdd: function() {
        var _that = this;
        var win = _that.lookupReference('meetingAddWindow');
        if (!win) {
            win = Ext.create('Ext.window.Window', {
                    title: '新增会商',
                    width: 530,
                    maxHeight: 550,
                    closeAction: 'hide',
                    autoScroll: true,
                    reference: 'meetingAddWindow',
                    buttons: [

                        {
                            text: '保存',
                            handler: function() {
                                var form = win.items.items[0].getForm();
                                if (form.isValid()) {
                                    var modal = this.up('window');
                                    var meeetingGrid = _that.lookupReference('meetingGrid');
                                    var store = meeetingGrid.getStore();
                                    var values = form.getValues();
                                    values.river = config.RIVER;
                                    Ext.Ajax.request({
                                        url: config.URL + '/szy/dispatch/meeting/ddsSCon/save',
                                        method: "post",
                                        success: function(response, opts) {
                                            var result = Ext.JSON.decode(response.responseText);
                                            Ext.MessageBox.hide();
                                            if (result.code === 1) {
                                                Ext.Msg.alert('系统提示', "保存成功");
                                                store.reload();
                                                modal.hide();
                                            } else {
                                                Ext.Msg.alert("系统提示", '保存失败');
                                            }
                                        },
                                        failure: function() {
                                            Ext.Msg.alert('系统提示', '系统出错！');
                                        },
                                        params: values
                                    });
                                } else {
                                    Ext.Msg.alert('提示', '表单填写不合法！');
                                }
                            }
                        },
                        {
                            text: '取消',
                            handler: function() {
                                var modal = this.up('window');
                                modal.hide()
                            }
                        },
                    ],
                    items: {
                        xtype: 'meetingForm',
                        border: false,
                        reference: 'meetingAddForm'
                    }
                })
                // this.getView().add(win)
                // Ext.ComponentQuery.query('#mainView')[0].add(win);
        }
        win.show();
    },

    //修改应急事件
    meetingUpdata: function(grid, rowIndex, colIndex) {
        var rec = grid.getStore().getAt(rowIndex);
        rec.data.dt = rec.data.dt ? new Date(rec.data.dt) : "";
        var _that = this;
        var win = this.lookupReference('meetingUpdataWindow');
        var saveUpdata = function() {
            var form = _that.lookupReference('meetingUpdataForm').getForm();
            if (form.isValid()) {
                var modal = this.up('window');
                var meetingGrid = _that.lookupReference('meetingGrid');
                var store = meetingGrid.getStore();
                var values = form.getValues();
                values.river = config.RIVER;
                Ext.Ajax.request({
                    url: config.URL + '/szy/dispatch/meeting/ddsSCon/update',
                    method: "post",
                    success: function(response, opts) {
                        Ext.MessageBox.hide();
                        var result = Ext.JSON.decode(response.responseText);
                        if (result.code === 1) {
                            Ext.Msg.alert('系统提示', "修改成功");
                            store.reload();
                            modal.hide();
                        } else {
                            Ext.Msg.alert("系统提示", '修改失败');
                        }
                    },
                    failure: function() {
                        Ext.Msg.alert('系统提示', '系统出错！');
                    },
                    params: values
                });
            } else {
                Ext.Msg.alert('提示', '表单填写不合法！');
            }
        };
        if (!win) {
            win = Ext.create('Ext.window.Window', {
                title: '修改会商',
                width: 530,
                maxHeight: 550,
                //				modal: false,
                // layout: 'fit',
                closeAction: 'hide',
                autoScroll: true,
                reference: 'meetingUpdataWindow',
                buttons: [{
                        text: '保存',
                        handler: saveUpdata
                    },
                    {
                        text: '取消',
                        handler: function() {
                            var modal = this.up('window');
                            // _that.lookupReference('meetingUpdataForm').getForm().reset();
                            modal.hide()
                        }
                    },

                ],
                items: {
                    xtype: 'meetingForm',
                    border: false,
                    reference: 'meetingUpdataForm'
                }
            });
            this.getView().add(win);
        }
        win.show()
        this.lookupReference('meetingUpdataForm').getForm().reset();
        this.lookupReference('meetingUpdataForm').getForm().setValues(rec.data)
    },
});